using System.Collections.Generic;
using Animancer;
using MoonFramework.Template;
using Sirenix.OdinInspector;
using UnityEngine;

namespace Config
{
	public enum ItemType
	{
		[LabelText("装备")] Weapon,
		[LabelText("消耗品")] Consumable,
		[LabelText("材料")] Material
	}
	
	/// <summary>
	/// 武器类型
	/// </summary>
	public enum WeaponType
	{
		[LabelText("空")] None,
		[LabelText("斧")] Axe,
		[LabelText("镐")] Pickaxe,
		[LabelText("镰刀")] Sickle
	}

	/// <summary>
	/// 物品类型信息的接口
	/// </summary>
	public interface IItemType
	{
		
	}
	
	public class ItemWeaponInfo : IItemType
	{
		[LabelText("武器类型")] public WeaponType WeaponType;
		[LabelText("角色手上武器预制体")] public GameObject PrefabOnActor;
		[LabelText("武器坐标")] public Vector3 Position; //相对与角色的位置
		[LabelText("武器旋转")] public Vector3 Rotation;
		[LabelText("武器动画")] public ClipTransition WeaponAnimation;
		[LabelText("待机动画")] public ClipTransition IdleAnimation;
		
		[LabelText("攻击力")] public float AttackValue;
		[LabelText("损耗")] public float WearValue;
		[LabelText("攻击距离")] public float AttackDistance;
		
		[LabelText("攻击音效")] public AudioClip AttackAudio;
		[LabelText("命中音效")] public AudioClip HitAudio;
		[LabelText("命中粒子")] public string HitEffect;
	}

	public abstract class BaseUsableItemInfo : IItemType
	{
		[LabelText("数量上限")] public float MaxCount;
	}
	
	public class ItemConsumableInfo :BaseUsableItemInfo
	{
		[LabelText("恢复生命值")] public float RecoverHp;
		[LabelText("恢复饥饿值")] public float RecoverHunger;
	}

	public class ItemMaterialInfo :BaseUsableItemInfo
	{
	}

	/// <summary>
	/// 物品配置
	/// </summary>
	[CreateAssetMenu(menuName = "Config/物品配置")]
	public class ItemConfig : BaseConfig
	{
		[LabelText("名称")] public string Name;
		[LabelText("类型"), OnValueChanged(nameof(OnItemTypeChanged))] public ItemType ItemType;
		[LabelText("地图物品ID")] public int MapObjectConfigID;
		[LabelText("描述"), MultiLineProperty] public string Description;
		[LabelText("图标")] public Sprite Icon;
		[LabelText("类型专属信息")] public IItemType ItemTypeInfo;
		
		private static readonly Dictionary<ItemType, IItemType> _itemTypeInfos = new()
		{
			{ItemType.Weapon, new ItemWeaponInfo()},
			{ItemType.Consumable, new ItemConsumableInfo()},
			{ItemType.Material, new ItemMaterialInfo()}
		};
		
		/// <summary>
		/// 当类型修改的时候，自动生成同等类型应有的专属信息
		/// </summary>
		private void OnItemTypeChanged()  => ItemTypeInfo = _itemTypeInfos[ItemType];
	}
}
